﻿using Core.DomainServices;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace Infrastructure.DomainServices
{
    public class AppConfig : IAppConfig
    {
        public string OutputFolder
        {
            get
            {
                try
                {
                    return ConfigurationManager.AppSettings["WorkingFolder"].ToString();
                }catch{
                    return Directory.GetCurrentDirectory().Replace("bin" + Path.DirectorySeparatorChar + "Debug", "DataSample");
                }
            }
        }
        public Dictionary<string, string> GetXMLValues()
        {

            string xmlFilePath = Directory.GetCurrentDirectory().Replace("bin" + Path.DirectorySeparatorChar + "Debug", "DataSample") + Path.DirectorySeparatorChar + "CompanyInformation.xml";
            Dictionary<string, string> dictionaryObject = new Dictionary<string, string>();
            try
            {
                if (File.Exists(xmlFilePath))
                {
                    XmlDocument ccdDocument = new XmlDocument();
                    ccdDocument.Load(xmlFilePath);
                    XmlNodeList xmlNodelist = ccdDocument.SelectNodes("section");
                    foreach (XmlElement node in xmlNodelist[0].ChildNodes)
                    {
                        dictionaryObject.Add(node.Attributes[0].Value, node.Attributes[1].Value);
                    }
                }
                return dictionaryObject;
            }
            catch (Exception)
            {
                return null;
            }
        }
    }
}
